package com.ysd.controller;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ysd.entity.Read_room;
import com.ysd.repository.Read_room_repository;
import com.ysd.utils.Result;


@RestController
public class Read_roomController {
		
	@Autowired
	private Read_room_repository rRepos;
	
	//��ѯ������Դ
	@RequestMapping("getRoom")
	public Object  getRoom() {
		List<Read_room>	list=rRepos.findAll();
		long	number=rRepos.count();
		int count=(int)(number);
		if (list!=null) {
			return Result.toClient("0", "��ȡ�ɹ�", count, list);
		} else {
			return Result.toClient("1", "��ȡʧ��",null,null);
		}
		
	}
	
	//�����Դ
	@RequestMapping("addRoom")
	public Object addRoom(String read_room_name,String read_romm_remark) {
				
		int	n=rRepos.addRoom(read_room_name, read_romm_remark);
		if (n>0) {
			return Result.toClient("0", "��ӳɹ�", null);
		} else {
			
			return Result.toClient("1", "���ʧ��", null);
		}
	}
	
	//ɾ����Դ
	@RequestMapping("deleteRooms")
	public Object deleteRooms(int read_romm_id) {
			try {
				rRepos.delete(read_romm_id);
				return Result.toClient("0", "ɾ���ɹ�", null);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return Result.toClient("1", "ɾ��ʧ��", null);
			}
	}
	
	@RequestMapping("updateRoom")
	public Object updateRoom(String read_room_name,String read_romm_remark,int read_romm_id) {
		int	n=rRepos.updateRoom(read_room_name, read_romm_remark, read_romm_id);
				if (n>0) {
					return Result.toClient("0", "�޸ĳɹ�", null);
				} else {

					return Result.toClient("1", "�޸�ʧ��", null);
				}
		
	}
}
